package model;

import java.rmi.AlreadyBoundException;
import java.util.Comparator;

public class Vokabel
{
	private String id;
	private String german;
	private String english;
	private int lvlGerman;
	private int lvlEnglish;
	
	
	public Vokabel(String german, String english, int lvlGerman, int lvlEnglish)
	{
		setGerman(german);
		setEnglish(english);
		setLvlGerman(lvlGerman);
		setLvlEnglish(lvlEnglish);
	}
	
	public String getId()
	{
		return id;
	}
	
	public void setId( String id ) 
	{
		if(id == null)
			throw new NullPointerException("Vokabel setId: Id must not be null");
		if (this.id != null)
			throw new IllegalArgumentException("Vokabel setId: Id is already set");
			
		this.id = id;
	}

	public String getGerman()
	{
		return german;
	}

	public void setGerman(String german)
	{
		if(german == null )
			throw new NullPointerException("Vokabel setGerman: value must not be null");
		
		this.german = german;
	}

	public String getEnglish()
	{
		return english;
	}

	public void setEnglish(String english)
	{
		if(english == null )
			throw new NullPointerException("Vokabel setEnglish: value must not be null");
		
		this.english = english;
	}

	public int getLvlGerman()
	{
		return lvlGerman;
	}

	public void setLvlGerman(int lvlGerman)
	{
		if( lvlGerman < 1 || lvlGerman > 5)
			throw new IllegalArgumentException("Vokabel setLvLGerman: allowd values 1-5");
		
		this.lvlGerman = lvlGerman;
	}

	public int getLvlEnglish()
	{
		return lvlEnglish;
	}

	public void setLvlEnglish(int lvlEnglish)
	{
		if( lvlEnglish < 1 || lvlEnglish > 5)
			throw new IllegalArgumentException("Vokabel setlvlEnglish: allowd values 1-5");
		
		this.lvlEnglish = lvlEnglish;
	}
	
	//-------------other methods------------------
	
	public void raiseLvlGerman()
	{
		if(lvlGerman < 5)
			lvlGerman++;
	}
	
	public void raiseLvlEnglish()
	{
		if(lvlEnglish < 5)
			lvlEnglish++;
	}
	
	public void decreaseLvlGerman()
	{
		if (lvlGerman > 1)
			lvlGerman--;
	}
	
	public void decreaseLvlEnglish()
	{
		if (lvlEnglish > 1)
			lvlEnglish--;
	}
	
	
	
	//----------------------Comperator-------------------------------
	
	public static class SortByGermanVokabel implements Comparator<Vokabel>
	{

		@Override
		public int compare(Vokabel arg0, Vokabel arg1)
		{
			return arg0.getGerman().compareToIgnoreCase(arg1.getGerman());
		}
	}
	
	public static class SortByEnglishVokabel implements Comparator<Vokabel>
	{

		@Override
		public int compare(Vokabel arg0, Vokabel arg1)
		{
			return arg0.getEnglish().compareToIgnoreCase(arg1.getEnglish());
		}
	}
	
}
